#pragma once

#include "common.h"
#include "Memory_pools.h"
#include "page_map.h"

// 单例
class PageCache
{
public:
    static PageCache *GetInstance()
    {
        return &_Inst;
    }

    Span* MapObjictToSpan(void *obj);

    void ReleaseSpanTOPageCache(Span *span);

    // 获取k页span
    Span* NewSpan(size_t k);

    std::mutex _pageMtx;
private:
    PageCache()
    {
    }
    PageCache(const PageCache &) = delete;

    SpanList _spanLists[NPAGES]; // Span哈希桶

    //std::unordered_map<PAGE_ID, Span*> _idSpanMap; // 建立页号和Span的映射关系
    //TCMalloc_PageMap1<32 - PAGE_SHIFT> _idSpanMap;
    //TCMalloc_PageMap2<32 - PAGE_SHIFT> _idSpanMap;
    TCMalloc_PageMap3<64 - PAGE_SHIFT> _idSpanMap;

    ObjectPool<Span> _spanPool;

    static PageCache _Inst;
};